package com.jl.core.controller;

import com.jl.config.BaseResponse;
import com.jl.core.service.UserService;
import com.jl.model.vo.UserVo;
import com.jl.utils.UserInfoContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
@Slf4j
@Api(description = "用户")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("getUserInfo")
    @ApiOperation(value = "获取用户信息")
    public BaseResponse<UserVo> getUserInfo(){
        return BaseResponse.success(UserInfoContext.getUser());
    }

    @GetMapping("bindPhone")
    @ApiOperation(value = "绑定手机")
    public BaseResponse bindPhone(String phone,String code,String password,String password2){
        userService.bindPhone(phone,code,password,password2);
        return BaseResponse.success();
    }

    @GetMapping("getCode")
    @ApiOperation(value = "获取验证码")
    public BaseResponse getCode(String phone){
        userService.getCode(phone);
        return BaseResponse.success();
    }
}
